# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Andrey Mivrenik <gim at fastmail dot fm>
# Contributor: Tim Diels <tim@timdiels.be>

_name=dropbox-sdk-python
pkgname=python-dropbox
pkgver=11.36.1
pkgrel=3
pkgdesc="Python SDK for Dropbox Core APIs"
url="https://github.com/dropbox/dropbox-sdk-python"
arch=(any)
license=(MIT)
depends=(
  python
  python-requests
  python-setuptools  # for dropbox.session
  python-six
  python-stone
  python-urllib3
)
makedepends=(
  python-build
  python-installer
  python-setuptools-scm
  python-pytest-runner
  python-wheel
)
checkdepends=(
  python-ply
  python-pytest
  python-pytest-mock
)
source=($url/archive/v$pkgver/$_name-v$pkgver.tar.gz)
sha512sums=('29db18efa9059744d6e18f3f15eaee9161df0e26af947fac3fdf3d7e906380f499c1ecc4b2c14a5207c879cd282b73dea44a1dc664f27be99fbe2cd309b86f09')
b2sums=('ed2586c27e020cae38dafdee7367ea38ad191a6275ab677adef13cf3b3c2eec1fab204d6845a7108b33a925a41459053eb5d33bd5a5c0be771613e9f89f775d7')

prepare() {
  cd $_name-$pkgver
  # remove strict version dependencies
  # remove broken version specifiers
  sed -e 's/==/>=/;s/2\.\*/2.0/' -i setup.py requirements.txt test/requirements.txt
  # don't use mock
  sed -e 's/import mock/from unittest import mock/' -i test/unit/test_dropbox_unit.py
  # Fix version
  sed -e "s|0.0.0|$pkgver|" -i dropbox/dropbox_client.py
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$site_packages:$PYTHONPATH"
  pytest -vv --ignore test/integration/
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
